what is purpose of command smove in redis? - database

in redis for moving on set collection to the another set collection we can use "smove" command as
bellow :
smove set1 set2 member
and my question is this operation , solve what`s problem .
if someone has good answer , tell me please

Without this command you would have to remove and item from set1 and add it to set2.
This is not atomic.
If your process died in the middle you would lose that set entry before it was added to set2
https://redis.io/commands/smove has more information

Related

Unable to add items to Roblox Table

I am having difficulty troubleshooting some code.
I have a for loop and in it I clone a part (called EnemySiteHub).
I expect that I can store each cloned part to a table (called EnemySiteTable).
Unfortunately, even though the loop runs successfully and I actually see the cloned EnemySiteHubs during a run of the game.. The table is size remains 0.
Trying to access the table in code gives a nil error.
Code snip:
local ENEMYSITE_COUNT = 5
local EnemySiteTable = {} -- [[ Store the table of enemy site objects ]]
-- Loops until there are the amount of enemy site hubs set in ENEMYSITE_COUNT
for i = 1, ENEMYSITE_COUNT do
--Makes a copy of EnemySiteHub
local enemySite = ServerStorage.EnemySites.EnemySiteHub:Clone()
enemySite.Parent = workspace.EnemySites
EnemySiteTable[i] = enemySite
This line of code causes causes the error below.
local enemySiteTableSize = #enemySiteTable
18:12:37.984 - ServerScriptService.MoveEnemyToSite:15: attempt to get length of a nil value
Any help will be appreciated.
#array is used to retrieve the length of arrays. You will have to use some sort of table.function() or use a for i,v in pairs(EnemySiteTable) loop.
Here's some more information: https://developer.roblox.com/en-us/articles/Table
Thanks #pyknight202
The problem originated somewhere else in my code.
The EnemySiteTable is in a module script.
This code below is the correct code to give access to the EnemySiteTable
--Have the table of enemies accessible
EnemySiteManager.EnemySiteTable = EnemySiteTable
I had an error (typo) in that line of code.
The effect of that error kept returning a nil table, giving a table size of 0.

How to find out every time a stored procedure has run

Is there a way to find out every single time a stored procedure has run in the last X amount of days? There are ways to see the last time it ran, but what if I want to see the last X number of times.
I can't find anything when I searched. Any suggestions?
I would suggest that you take advantage of the ability of Extended Events to capture a histogram. You can set it up like this:
CREATE EVENT SESSION [ProcedureExecutionCount]
ON SERVER
ADD EVENT sqlserver.rpc_completed
(SET collect_statement = (0)
WHERE (
[sqlserver].[equal_i_sql_unicode_string]([sqlserver].[database_name], N'AdventureWorks')
AND [object_name] = N'AddressByCity'
)
)
ADD TARGET package0.histogram
(SET filtering_event_name = N'sqlserver.rpc_completed', source = N'object_name', source_type = (0));
That will now, only, ever, count the number of times that procedure, on that database, is executed. Nice, simple, clean and easy.
There are several ways to do it. Visit here: https://www.mssqltips.com/sqlservertip/3259/several-methods-to-collect-sql-server-stored-procedure-execution-history/

Batch edit column fields of selected rows via phpMyAdmin

I have a picture gallery (built with Coppermine) and I'm trying to backdate a bunch of pictures; to do so I know that I have to edit two columns (mtime and ctime) in the coppermine DB.
Both columns are contained in a table named 'db_pictures'.
I have already done that manually and I know it works.
Now the problem is that I have to edit approx 300-400 pictures (=300-400 rows, 1 row per picture) in the 'db_pictures' table and it would take forever to do that manually.
I thought this could be done quicky and effortlessy with the right command so I searched the site and found this; unfortunately I get a syntax error when I try to apply this command:
UPDATE db_pictures SET ctime=[new value] WHERE [old value]
What am I doing wrong? Could somebody tell me how to apply the right command, please?
Condition in WHERE clause must evaluate to a boolean value i.e. ´true´ or false, see UPDATE Syntax:
UPDATE db_pictures SET ctime=[new value] WHERE ctime=[old value]
or, as your question seems to be a bit unclear,
UPDATE db_pictures SET ctime=[new value] WHERE mtime=[old value]

MEL: Traverse through hierarchy

I'm writing a MEL script that will rename all of the joints in a joint hierarchy to a known format. The idea is that you would select the Hip joint and the script would rename the Hips, and go through every other joint and rename it based on its position in the hierarchy.
How can you traverse through a joint hierarchy in MEL?
If you assign to $stat_element the name of your top joint in the hierarchy and run the following code, it will add a prefix "myPrefix_" to all children elements of that joint.
string $stat_element = "joint1";
select -r $stat_element;
string $nodes[] = `ls -sl -dag`;
for($node in $nodes){
rename -ignoreShape $node ("myPrefix_" + $node);
}
Hope this helps
If you need to make detailed decisions as you go along, instead of bulk-renaming, traversing the hierarchy is pretty simple. The command is 'listRelatives'; With the 'c' flag it returns children of a node and with the 'p' flag it returns the parent. (Note that -p returns a single objects, -c returns an array)
Joint1
Joint2
Joint3
Joint4
listRelatives -p Joint2
// Result: Joint1 //
listRelatives -c Joint2
// Result: Joint3, Joint4
The tricky bit is the renaming, since maya will not always give you the name you expect (it won't allow duplicate names at the same level of the hierarchy). You'll need to keep track of the renamed objects or you won't be able to find them after they are renamed in case the new names don't match your expectations.
If you need to keep track of them, you can create a set with the set command before renaming; no matter what becomes of the names, all of the objects will still be in the set. Alternatively, you can traverse the hierarchy by selecting objects and renaming the current selection -- this won't record the changes but you won't have problems with objects changing names in the middle of your operation and messing up your commands.
It can be messy to do this in MEL if you have non-unique names because the handle you have for the object is the name itself. Once you rename a parent of a node with a non-unique name, the child's name is different. If you stored the list of all names before starting to rename, you will get errors as the rename command will attempt to rename nodes that don't exist. There are 2 solutions I know of using MEL. But first, here's the pyMel solution which is much easier and I recommend you use it.
PyMel Solution:
import pymel.core as pm
objects = pm.ls(selection=True, dag=True, type="joint")
pfx = 'my_prefix_'
for o in objects:
o.rename(pfx + o.name().split('|')[-1])
As pm.ls returns a list of real objects, and not just the names, you can safely rename a parent node and still have a valid handle to its children.
If you really want to do it in MEL, you need to either rename from the bottom up, or recurse so that you don't ask for the names of children before dealing with the parent.
The first MEL solution is to get a list of long object names and sort them based on their depth, deepest first. In this way you are guaranteed to never rename a parent before its children. The sorting bit is too convoluted to be bothered with here, and the recursive solution is better anyway.
Recursive MEL solution:
global proc renameHi(string $o, string $prefix) {
string $children[] = `listRelatives -f -c -type "joint $o`;
for ($c in $children) {
renameHi( $c ,$prefix ) ;
}
string $buff[];
int $numToks = tokenize($o, "|", $buff);
string $newName = $buff[( $numToks - 1)];
$newName = ($prefix + $newName);
rename($o,$newName);
}
string $prefix = "my_prefix_";
string $sel[] = `ls -sl -type "joint"`;
for ($o in $sel) {
renameHi($o, $prefix);
}
This recursive solution drills down to the leaf nodes and renames them before renaming their parents.

Velocity: populating a list with dates from "today" to an arbitratily-set point in the past

I want to populate a drop-down list with months from the current month to a fixed date in the past using Velocity. I'm not certain if this is possible, since the only loop that is available is foreach and I do not know if there is a sensible way to populate the array the foreach will loop through.
Is this kind of thing simply not something I can do with Velocity? I could achieve it quite easily with Javascript, but for accessibility reasons I'd prefer it to be created by the server.
Yes, this can definitely be done. Check out the DateTool from the VelocityTools project and recall that you can create and populate ArrayLists in VTL:
#set( $arr = [1, 2, 'foo', $bar] )
or
#set( $nums = [1..12] )
or directly:
#foreach( $num in [1..12] )$num #end ##this is pretty much a for loop
But really, you can also populate the array in java and then drop it into your context. Often that is better than building model data in your view.

Resources